package com.ycrlkj.android.modulespublic.common.base;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import androidx.annotation.NonNull;
import java.util.List;

/**
 * 官方package android.widget;包里带的 ArrayAdapter<T> 功能够用,
 * 但是有个问题, spinner组件有不必要的 padding 值, 造成 spinner组件 和 其它组件对不齐
 * 此类只是做了 getView 方法的重写, 去掉了 spinner组件 的左侧内缩进, 即下面代码
 * view.setPadding(0, view.getPaddingTop(), view.getPaddingRight(), view.getPaddingBottom());
 *
 */
public class MArrayAdapter<T> extends ArrayAdapter<T> {


    public MArrayAdapter(@NonNull Context context, int resource) {
        super(context, resource);
    }

    public MArrayAdapter(@NonNull Context context, int resource, int textViewResourceId) {
        super(context, resource, textViewResourceId);
    }

    public MArrayAdapter(@NonNull Context context, int resource, @NonNull T[] objects) {
        super(context, resource, objects);
    }

    public MArrayAdapter(@NonNull Context context, int resource, int textViewResourceId, @NonNull T[] objects) {
        super(context, resource, textViewResourceId, objects);
    }

    public MArrayAdapter(@NonNull Context context, int resource, @NonNull List<T> objects) {
        super(context, resource, objects);
    }

    public MArrayAdapter(@NonNull Context context, int resource, int textViewResourceId, @NonNull List<T> objects) {
        super(context, resource, textViewResourceId, objects);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view = super.getView(position, convertView, parent);
        view.setPadding(0, view.getPaddingTop(), view.getPaddingRight(), view.getPaddingBottom());
        return view;
    }
}
